﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Server.Models;
using Server.UserService;

namespace Server.UserManage
{
    public class UserBLL
    {
        UserDAL uDal = new UserDAL();
        public void UserAdd(UserInfo user)
        {
            try
            {
                uDal.UserAdd(user);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void UserEdit(UserInfo user)
        {
            try
            {
                uDal.UserEdit(user);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void UserState(UserInfo user)
        {
            try
            {
                uDal.UserState(user);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public UserInfo GetUserByID(int id)
        {
            try
            {
                return uDal.GetUserByID(id);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public UserInfo[] GetUserList()
        {
            try
            {
                return uDal.GetUserList();
            }
            catch (Exception)
            {
                throw;
            }
        }
        #region 设备管理
        public void DeviceAdd(DeviceInfoModel dev)
        {
            try
            {
                uDal.DeviceAdd(dev);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void DeviceDel(int id)
        {
            try
            {
                uDal.DeviceDel(id);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public DeviceInfoModel[] GetDeviceList()
        {
            try
            {
                var dt = uDal.GetDeviceList();
                DeviceInfoModel[] dev = new DeviceInfoModel[dt.Rows.Count];
                for (int i = 0; i < dev.Length; i++)
                {
                    var dr = dt.Rows[i];
                    dev[i] = new DeviceInfoModel()
                    {
                        id = Convert.ToInt32(dr["id"]),
                        DeviceSession = dr["DeviceSession"].ToString(),
                        SessionExpired = Convert.ToDateTime(dr["SessionExpired"]),
                        DeviceIP = dr["DeviceIP"].ToString(),
                        Number = Convert.ToInt32(dr["Number"]),
                        Remark = dr["Remark"].ToString()
                    };
                }
                return dev;
            }
            catch (Exception)
            {
                throw;
            }
        }
        #endregion

    }
}
